<?php
/**
编辑管理员页面
 */
//编辑需关联数据库,需先获取admin_id
$adminId = $_GET['admin_id'];

//检测管理员Id
if (empty($adminId)){
    echo "管理员id错误"."<br/>";
    echo "<a href='javascript:history.go(-1)'>返回上一页</a>";
    exit();
}

//开启session
session_start();

//连接到数据库
$dsn = "mysql:host=127.0.0.1;dbname=blog";
$db = new PDO($dsn, "root", "123456");

//更改默认的utf8为utf8mb4以防中文乱码
$db->exec("set names utf8mb4");

//php语句mysql查询相关数据
$sql = "select * from admin where admin_id = '$adminId'";
$result = $db->query($sql);
$adminEdit = $result->fetch(PDO::FETCH_ASSOC);

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/base.css" />
    <link rel="stylesheet" type="text/css" href="css/top.css" />
    <link rel="stylesheet" type="text/css" href="css/right.css" />
    <link rel="stylesheet" type="text/css" href="css/left.css" />
</head>
<body>
<div id="container">
    <div id="top">
        <div id="top_left">
            <span>博客管理系统</span>
        </div>
        <div id="top_right">
            欢迎你：<?php echo $_SESSION['admin_name'] ?> <a href="logout.php">退出登录</a>
        </div>
    </div>
    <div id="left">
        <ul>
            <li><a href="#">分类管理</a></li>
            <li><a href="#">文章管理</a></li>
            <li><a href="#" id="left_two">管理员</a></li>
        </ul>
    </div>
    <div id="right">
        <ul>
            <li>
                <a href="#">首页</a>&nbsp;>
                <a href="#">管理员操作</a>&nbsp;>
                <a href="#">管理员列表</a>
            </li>
            <li>
                <form id="admin_edit_form" action="admin_edit_save.php" method="post">
                    <table class="add">
                        <tbody>
                        <tr>
                            <td width="190">管理员id:&nbsp;</td>
                            <td><input type="text" value="<?php echo $adminEdit['admin_id']; ?>" readonly="readonly" name="admin_id"/></td>
                        </tr>
                        <tr>
                            <td>管理员名称:&nbsp;</td>
                            <td>
                                <input type="text" name="admin_name" value="<?php echo $adminEdit['admin_name']; ?>"/>
                            </td>
                        </tr>
                        <tr>
                            <td>管理员邮箱:&nbsp;</td>
                            <td>
                                <input type="text" name="admin_email" value="<?php echo $adminEdit['admin_email']; ?>"/>
                            </td>
                        </tr>
                        <tr>
                            <td>初始密码:&nbsp;</td>
                            <td>
                                <input type="text" name="admin_password" value=""/>
                            </td>
                        </tr>
                        <tr>
                            <td>修改密码:&nbsp;</td>
                            <td>
                                <input type="text" name="edit_password" value=""/>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <input type="submit" class="button" />
                                <input type="reset" class="button" />
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </li>
        </ul>
    </div>
</div>
</body>
</html>
